<template>
    <rx-layout>
        <div slot="center" style>
            <rx-fit>
                <div slot="toolheader" foldheader="true" foldbtn="false" border="false">
                    <div class="table-operator">
                        <rx-button alias="sysLogDelete" :butn-icon="'delete'"
                                   :butn-type="'primary'"
                                   :show-no-right="true" @click="delByIds(selectedRowKeys)">{{$ti18('rxList.delBtn','删除')}}
                        </rx-button>
                        <rx-button :butn-icon="'retweet'"
                                   :butn-type="'danger'"
                                   :show-no-right="true" @click="deleteAll">{{i18n('list.clearBtn','清空')}}
                        </rx-button>

                    </div>
                    <span class="search-btn-box">
                <span class="search-btn" @click="searchshow"><i class="iconfont iconguolv"></i>{{$ti18('rxList.leachBtn','过滤')}}</span>
           </span>
                </div>
                <div slot="searchbar" btnalign="right" v-if="fitSearch" @search="search" @cancel="cancel"
                     @close="close">
                    <a-form layout="vertical">
                        <a-form-item :label="i18n('form.appName','应用名称')">
                            <a-input :placeholder="i18n('form.appName','应用名称','input')" v-model="queryParam.Q_APP_NAME__S_LK"/>
                        </a-form-item>
                        <a-form-item :label="i18n('form.method','方法名')">
                            <a-input :placeholder="i18n('form.method','方法名','input')" v-model="queryParam.Q_METHOD_NAME__S_LK"/>
                        </a-form-item>
                        <a-form-item :label="i18n('form.pkValue','业务主键')">
                            <a-input :placeholder="i18n('form.pkValue','业务主键','input')" v-model="queryParam.Q_PK_VALUE__S_LK"/>
                        </a-form-item>
                        <a-form-item :label="i18n('form.ip_','IP_')">
                            <a-input :placeholder="i18n('form.ip_','IP_','input')" v-model="queryParam.Q_IP__S_LK"/>
                        </a-form-item>
                        <a-form-item :label="i18n('form.extend','扩展信息')">
                            <a-input :placeholder="i18n('form.extend','扩展信息','input')" v-model="queryParam.Q_EXTEND__S_LK"/>
                        </a-form-item>
                        <a-form-item :label="i18n('form.isRestore','是否需要恢复')">
                            <a-select allowClear v-model="queryParam.Q_IS_RESUME__S_EQ">
                                <a-select-option value="YES">{{i18n('form.yes','是')}}</a-select-option>
                                <a-select-option value="NO">{{i18n('form.no','否')}}</a-select-option>
                            </a-select>
                        </a-form-item>
                    </a-form>
                </div>
                <rx-grid
                    ref="table"
                    :allowRowSelect="true"
                    :multiSelect="true"
                    :columns="columns"
                    :defaultPageSize="10"
                    url="/api-system/system/core/sysLog/query"
                    :queryParam="queryParam"
                    data-field="result.data"
                    :pageSizeOptions="['10','30','40']"
                    id-field="id"
                    @selectChange="onSelectChange"
                >
          <span slot="action" slot-scope="{ text, record }" class="actionIcons">
            <span @click="detail(record)">{{$ti18('rxList.detailBtn','明细')}}</span>
            <span v-if="record.isResume=='NO'" @click="resume(record)">{{i18n('list.restore','恢复')}}</span>
          </span>
                </rx-grid>
            </rx-fit>
        </div>
    </rx-layout>
</template>

<script>
import SysLogApi from '@/api/system/core/sysLog'
import {BaseList, RxFit, RxGrid, Util} from "@lowcode/jpaas-common-lib";
import SysLogDetail from "./SysLogDetail";
import SysLogFormResume from "./SysLogFormResume";
import SysErrorLogApi from "@/api/system/core/sysErrorLog";

export default {
    name: 'SysLogList',
    mixins: [BaseList],
    components: {
        RxFit
    },
    data() {
        return {
            columns: [
                {
                    title: this.$ti18('rxList.index','序号'),
                    type: 'indexColumn',
                    width: 60,
                    dataIndex: 'serial',
                    scopedSlots: {customRender: 'serial'}
                },

                {title: this.i18n('form.appName','应用名称'), dataIndex: 'appName', width: 140},
                {title: this.i18n('form.module','模块'), dataIndex: 'module', width: 100},
                {title: this.i18n('form.subModule','子模块'), dataIndex: 'subModule', width: 100},
                {title: this.i18n('form.pkValue','业务主键'), dataIndex: 'pkValue', width: 100},
                {title: this.i18n('form.method','方法名'), dataIndex: 'methodName', width: 120},
                {title: this.i18n('form.ipAddr','IP地址'), dataIndex: 'ip', width: 100},
                {title: this.i18n('form.operation','操作'), dataIndex: 'operation', width: 100},
                {title: this.i18n('form.userName','用户名'), dataIndex: 'userName', width: 100},
                {title: this.i18n('form.duration','执行时长(毫秒)'), dataIndex: 'duration', width: 170},
                {title: this.$ti18('rxForm.createTime','创建时间'), dataIndex: 'createTime', width: 140},
                {title: this.$ti18('rxList.action','操作'), width: 100, dataIndex: 'action',fixed:'right', scopedSlots: {customRender: 'action'}},

            ],
            comment: this.i18n('list.comment','系统日志'),
            detailcomponent: SysLogDetail,
            widthHeight: ['800px', '600px'],
            fitSearch: false,
        }
    },
    methods: {
        i18n(name,text,key){
            return this.$ti18(name,text,"SysLog",key);
        },
        delById(ids) {
            return SysLogApi.del({ids: ids.join(',')});
        },
        getListByParams(parameter) {
            return SysLogApi.query(parameter)
        },
        resume(record) {
            if (record.action == 'upd' || record.action == 'del') {
                var self_ = this;
                var conf = {
                    component: SysLogFormResume,
                    title: self_.i18n('list.restoreTitle','表单恢复'),
                    curVm: this,
                    data: {alias: JSON.parse(record.detail).alias,appId:record.appId},
                    widthHeight: ['200px', '400px']
                };
                Util.open(conf, function (action, data) {
                    if (action != 'ok') return;
                    self_.resumeByIds(record.id, data);
                })
            } else {
                this.resumeByIds(record.id);
            }

        },
        resumeByIds(ids, extParams) {
            SysLogApi.resumeByIds({ids: ids, extParams: extParams}).then(res => {
                this.resetSearch();
            })
        },
        deleteAll() {
            let self_ = this;
            this.$confirm({
                title: self_.$ti18('rxMsa.actionTips', '操作提示'),
                content:self_.i18n('msa.sureDelete','您确定要清空日志吗？'),
                okText: self_.$ti18("rxForm.okBtn", "确定"),
                cancelText: self_.$ti18("rxForm.cancelBtn", "取消"),
                onOk() {
                    SysLogApi.deleteAllSysLog().then(res => {
                        this.$refs.table.loadData()
                    })
                }
            })
        }

    }
}
</script>
<style scoped>

</style>

